import React, { Component } from "react";
// createPortal方法是用来将子组件挂载到父组件的dom层级以外去的，相当于vue的teleport组件
import { createPortal } from "react-dom";

class Child extends Component {
  state = {};
  render() {
    return createPortal(
      <div>这是child子组件</div>,
      document.querySelector("body")
    );
  }
}

class App extends Component {
  state = {};
  render() {
    return (
      <>
        <h2>portal传送门</h2>
        <div className="box">
          <Child />
        </div>
      </>
    );
  }
}

export default App;
